package com.gmm.springboot.admin.mapper.test01;

import java.util.Map;

import org.apache.ibatis.jdbc.SQL;

import com.gmm.common.StringUtil;

public class UserInfoSqlProvider {
	public String getSelectRecordSql(Map<String, Object> parameter) {

		return new SQL() {
			{
				SELECT("*");
				FROM("t_user_info");

				if (parameter.get("userId") != null) {
					WHERE("user_id=#{userId}");
				}
				ORDER_BY("user_id desc");

			}
		}.toString() + " limit #{beginIndex}, #{maxCount}";

	}

	public String getSelectCountSql(Map<String, Object> parameter) {

		return new SQL() {
			{
				SELECT("count(*)");
				FROM("t_user_info");

				if (parameter.get("userId") != null) {
					WHERE("user_id=#{userId}");
				}
			}
		}.toString();

	}

	public String getUpdateSql(UserInfo record) {

		return new SQL() {
			{
				UPDATE("t_user_info");

				if (StringUtil.isNotBlank(record.getUserName())) {
					SET("user_name = #{userName}");
				}
				if (record.getAge() != null) {
					SET("age=#{age}");
				}
				if (record.getRegisterTime() != null) {
					SET("register_time=#{registerTime}");
				}
				WHERE("user_id=#{userId}");
			}
		}.toString();

	}

}
